from django.shortcuts import render

# Create your views here
from rest_framework.generics import ListAPIView

from meiduo_mall.apps.goods.models import SKU
from drf_haystack.viewsets import HaystackViewSet

from meiduo_mall.utils.pagination import StandardResultsSetPagination
from .serializers import SKUIndexSerializer


class SKUSearchViewSet(HaystackViewSet):
    """
    SKU搜索
    """
    index_models = [SKU]
    serializer_class = SKUIndexSerializer
    pagination_class = StandardResultsSetPagination

class SKUListView(ListAPIView):
    def get_queryset(self):
        # 在视图中获取请求路径中的数据self.kwargs

        return SKU.objects.filter(category_id=self.kwargs['category_id'])

        # 序列化器
        serializer_class = SKUListSerializer

        # 分页
        pagination_class = StandardResultsSetPagination

        # 排序
        filter_backends = [OrderingFilter]
        # 指定排序字段
        ordering_fields = ('create_time', 'price', 'sales')
